package com.citywy.dao;

import com.citywy.domain.Account;
import org.apache.ibatis.annotations.One;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;

public interface AccountDao {
    /**
     * 查询所有账户，采用延迟加载的方式查询账户所属用户
     */
    @Select("select * from account")
    @Results(id="accountMap",
        value={
                @Result(id=true,column = "id",property = "id"),
                @Result(column = "uid",property = "uid"),
                @Result(column = "price",property = "price"),
                @Result(column = "summary",property = "summary"),
                @Result(column = "uid",
                        property = "user",
                        one=@One(select="com.citywy.dao.UserDao.findById",
                        fetchType = FetchType.LAZY)

                )
        })
    List<Account> findAll();


    /**
     * 根据用户ID查询account里的数据
     * @param uid
     * @return
     */
    @Select("select * from account where uid=#{uid}")
    List<Account> findByUid(int uid);
}
